package com.ming.rabbitmq.one;

import com.rabbitmq.client.*;

public class Consumer {

    public static final String QUEUE_NAME="hello";

    public static void main(String[] args) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("47.99.188.231");
        factory.setUsername("admin");
        factory.setPassword("123");
        factory.setPort(5672);
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        DeliverCallback deliverCallback=(consumerTag,message)->{
            System.out.println(new String(message.getBody()));
        };

        CancelCallback cancelCallback=consumerTag->{
            System.out.println("消息消费被取消");
        };
        System.out.println("C1正在等待接收消息：");
        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);

    }
}
